#define _CRT_SECURE_NO_WARNINGS 1

#include"Sort.h"

void TestBubbleSort()
{
	int a[] = { 1,5,8,32,9,23,56,7 };
	int sz = sizeof(a) / sizeof(a[0]);
	Print(a, sz);
	BubbleSort(a, sz);
	Print(a, sz);
}
void TestInsertSort()
{
	int a[] = { 9,8,7,6,5,4,3,2,1 };
	int sz = sizeof(a) / sizeof(a[0]);
	Print(a, sz);
	InsertSort(a, sz);
	Print(a, sz);
}

void TestHeapSort()
{
	int a[] = { 9,8,7,6,5,4,3,2,1 };
	int sz = sizeof(a) / sizeof(a[0]);
	Print(a, sz);
	HeapSort(a, sz);
	Print(a, sz);
}

void TestShellSort()
{
	int a[] = { 9,8,7,6,5,4,3,2,1 };
	int sz = sizeof(a) / sizeof(a[0]);
	Print(a, sz);
	ShellSort(a, sz);
	Print(a, sz);
}

void TestQuickSort()
{
	//int a[] = { 9,8,7,6,5,4,3,2,1,54,7,33,54,32,12,0,99};
	int a[] = { 9,8,7,6,5,4,3,2,1 };
	int sz = sizeof(a) / sizeof(a[0]);
	Print(a, sz);
	QuickSortNonR(a, 0,sz-1);
	Print(a, sz);
}

void TestMergeSort()
{
	//int a[] = { 9,8,7,6,5,4,3,2,1,54,7,33,54,32,12,0,99};
	int a[] = {1,5,3,2,7,8,4,6,7,8};
	int sz = sizeof(a) / sizeof(a[0]);
	Print(a, sz);
	MergeSortNonR(a, sz);
	Print(a, sz);
}
void TestCountSort()
{
	//int a[] = { 9,8,7,6,5,4,3,2,1,54,7,33,54,32,12,0,99};
	int a[] = {1,5,3,2,7,8,4,6,7,8};
	int sz = sizeof(a) / sizeof(a[0]);
	Print(a, sz);
	CountSort(a, sz);
	Print(a, sz);
}

void TestOP()
{
	srand((unsigned)time(NULL));
	int n = 1000000;
	int* n1 = (int*)malloc(sizeof(int) * n);
	int* n2 = (int*)malloc(sizeof(int) * n);
	int* n3 = (int*)malloc(sizeof(int) * n);
	int* n4 = (int*)malloc(sizeof(int) * n);
	int* n5 = (int*)malloc(sizeof(int) * n);
	int* n6 = (int*)malloc(sizeof(int) * n);
	int* n7 = (int*)malloc(sizeof(int) * n);

	for (int i = 0; i < n; i++)
	{
		n1[i] = rand()%n ;
		n2[i] = n1[i];
		n3[i] = n1[i];
		n4[i] = n1[i];
		n5[i] = n1[i];
		n6[i] = n1[i];
		n7[i] = n1[i];
	}

	int begin1 = clock();
	//BubbleSort(n1, n);
	int end1 = clock();

	int begin2 = clock();
	//InsertSort(n2, n);
	int end2 = clock();

	int begin3 = clock();
	HeapSort(n3, n);
	int end3 = clock();

	int begin4 = clock();
	ShellSort(n4, n);
	int end4 = clock();

	int begin5 = clock();
	QuickSortNonR(n5, 0,n-1);
	int end5 = clock();

	int begin6 = clock();
	MergeSortNonR(n6, n);
	int end6   = clock();

	int begin7 = clock();
	CountSort(n6, n);
	int end7 = clock();

	printf("BubbleSort:%d\n", end1 - begin1);
	printf("InsertSort:%d\n", end2 - begin2);
	printf("HeapSort:%d\n", end3 - begin3);
	printf("ShellSort:%d\n", end4 - begin4);
	printf("QuickSort:%d\n", end5 - begin5);
	printf("MergeSort:%d\n", end6 - begin6);
	printf("CountSort:%d\n", end7 - begin7);

}

int main()
{
	//TestBubbleSort();
	//TestInsertSort();
	//TestHeapSort();
	TestOP();
	//TestShellSort();
	//TestQuickSort();
	//TestMergeSort();
	//TestCountSort();
	return 0;
}